/*
 ID: brodyzt1
 PROG: palsquare
 LANG: C++
 */

#include <iostream>
#include <string>
#include <math.h>
#include <fstream>
#include <sstream>

using namespace std;

double Reverse(double number)
{
    double reverseNumber;
    double remainder;
    double ten = 10;
    while(number)
    {
        //extract the last digit from the number
        remainder = modf(number, &ten);
        
        //build the reverseNumber digit by digit
        reverseNumber = (reverseNumber * 10) + remainder;
        
        //exclude the last digit from the number
        //ready for the next evaluation
        number = number / 10;
    }
    return number;
}

string toString (double num)
{
    stringstream temp;
    temp.precision(30);
    temp << num;
    string tempString;
    temp >> tempString;
    return tempString;
}

string reversedString (string origString)
{
    stringstream tempStream;
    tempStream.precision(30);
    for (int i = 0; i < origString.length(); i++) {
        tempStream << origString[origString.length() - (1+i)];
    }
    string reversedString;
    tempStream >> reversedString;
    return reversedString;
}

string convertBases (int origNumber, int newBase)
{
    int quotient = origNumber;
    stringstream tempString;
    while (quotient != 0) {
        if ((quotient % newBase) < 10) {
            tempString << (quotient % newBase);
        }
        else
        {
             tempString << (char)(((quotient % newBase) % 10) + 65);
        }
        quotient = (quotient - (quotient % newBase)) / newBase;
    }
    string convertedString;
    tempString >> convertedString;
    return reversedString(convertedString);
}

bool isPalendrome (string origNumber)
{
    bool isPalendrome = true;
    if (origNumber[0] == '0') {
        isPalendrome = false;
    }
    if (origNumber != reversedString(origNumber)) {
        isPalendrome = false;
    }
    return isPalendrome;
}

int main(int argc, const char * argv[])
{
    ifstream input;
    input.open("palsquare.in");
    int base;
    input >> base;
    ofstream output;
    output.precision(30);
    output.open("palsquare.out");
    for (int i = 1; i <= 300; i++) {
        if (isPalendrome(convertBases(pow(i, 2), base))) {
            output << convertBases(i, base) << " " << convertBases(pow(i, 2), base) << "\n";
        }
    }
    return 0;
}

